<template>
    <div>
        <h1>登录</h1>
        <table class="table table-bordered" border="1px">
            <tbody>
                <tr>
                    <td>账户:</td>
                    <td>
                        <input type="text" v-model="info.name">
                    </td>
                </tr>
                <tr>
                    <td>密码:</td>
                    <td>
                        <input type="text" v-model="info.pwd">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <button value="提交" class="btn btn-primary" @click="ok">提交</button>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'
import axios from 'axios';
import { useRouter } from 'vue-router'
const router = useRouter();

let info: any = reactive({
    name: '',
    pwd: ''
})

const ok = () => {
    if (info.name == "") {
        alert('账户不能为空!');
        return;
    }
    if (info.pwd == "") {
        alert('密码不能空!');
        return;
    }
    axios({
        url: 'https://localhost:7056/api/User/Logn',
        method: 'get',
        params: info
    })
        .then((res) => {
            if (res.data == -1) {
                alert('用户名错误,联系管理员注册!');
                return;
            }
            else if (res.data == -2) {
                alert('密码错误!');
                return;
            }
            else if (res.data != "") {
                alert('登录成功！');
                return;
            }
            else {
                alert('登录失败!');
                return;
            }
        })
}
</script>

<style scoped></style>